package com.itcam.cm.manager.service.impl;

import com.itcam.cm.manager.mapper.OrderStatisticsMapper;
import com.itcam.cm.manager.service.OrderStatisticsService;
import com.itcam.cm.model.dto.order.OrderStatisticsDto;
import com.itcam.cm.model.entity.order.OrderStatistics;
import com.itcam.cm.model.vo.order.OrderStatisticsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Service
public class OrderStatisticsServiceImpl implements OrderStatisticsService {

    @Autowired
    OrderStatisticsMapper orderStatisticsMapper;


    @Override
    public void saveStatistics(List<OrderStatistics> orderStatistics) {
        for (OrderStatistics orderStatistic : orderStatistics) {
            orderStatisticsMapper.insertStatistic(orderStatistic);
        }
    }

    @Override
    public OrderStatisticsVo getOrderStatisticsData(OrderStatisticsDto orderStatisticsDto) {
        OrderStatisticsVo orderStatisticsVo = new OrderStatisticsVo();
        List<OrderStatistics> orderStatistics = orderStatisticsMapper.selectByData(orderStatisticsDto);
        for (OrderStatistics orderStatistic : orderStatistics) {
            LocalDate orderDate = orderStatistic.getOrderDate();
            BigDecimal totalAmount = orderStatistic.getTotalAmount();
            orderStatisticsVo.getDateList().add(orderDate.toString());
            orderStatisticsVo.getAmountList().add(totalAmount);
        }
        return orderStatisticsVo;
    }
}
